#include "p7zg.h"
#include "p7zg_log.h"
#include "p7zg_cui.h"
static int ProcessArgs(int argc, char** argv, int *fileCount, const char** target, const char*** fileV)
{
    int opt, i;
    while((opt = getopt(argc, argv, "t")) != -1){
    }
    if(optind+2 > argc){
        P7ZG_ERR(_("need at least 2 arguments, optind=%d, argc=%d\n"), optind, argc);
        goto ERR_OUT;
    }
    *fileCount = argc - optind - 1;
    *target = (const char*)argv[optind];
    *fileV = (const char* *)&argv[optind+1];
    P7ZG_DBG("target:\n %s\n", *target);
    P7ZG_DBG("files:\n");
    for(i=0; i<*fileCount; i++){
        P7ZG_DBG(" %s\n", (*fileV)[i]);
    }
    return 0;
ERR_OUT:
    return -1;
}

int main(int argc, char** argv)
{
    int ret;
    P7zgCUi ui;
    int fileCount;
    const char* target;
    const char** files;
    gtk_init(&argc, &argv);
    if(ProcessArgs(argc, argv, &fileCount, &target, &files)){
        goto ERR_OUT;
    }
    if(P7zgCUiInit(&ui, NULL, fileCount, target, files)){
        goto ERR_OUT;
    }
    P7zgCUiResetTo7z(&ui);
    ret = P7zgCUiRun(&ui);
    gtk_main();
    P7zgCUiExit(&ui);
    return ret;
ERR_OUT:
    return -1;
}
